home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15643 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.3 KB

  1. Path: solon.com!not-for-mail
  2. From: jcf3820@silver.sdsmt.edu (James Foster)
  3. Newsgroups: comp.lang.c,comp.lang.c.moderated
  4. Subject: Re: 8 Queens prog help
  5. Followup-To: comp.lang.c,comp.lang.c.moderated
  6. Date: 20 Apr 1996 13:22:16 -0500
  7. Organization: South Dakota School of Mines and Technology
  8. Sender: clc@solutions.solon.com
  9. Approved: clc@solutions.solon.com
  10. Message-ID: <4lba0o$lg3@solutions.solon.com>
  11. References: <4l87ud$73u@solutions.solon.com>
  12. NNTP-Posting-Host: solutions.solon.com
  13. X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
  14.  
  15. Mike Mitchell (72724.2067@CompuServe.COM) wrote:
  16. : Hi All!
  17. : Need some C help this week.  I'm currently working on a program 
  18. : called "Eight Queens".  Basically, I have to place 8 queen chess 
  19. : pieces on an 8x8 chess board without them checking one another.  
  20.  
  21. I had to program something similar in Data Structures, except that the
  22. user got to put in how many queens and rooks to place on a board and we
  23. had to find how many possible solutions.  However, the algorithm is pretty
  24. much the same.  Just follow this and you should be fine.
  25.  
  26. Try to put a queen on the board.
  27.  
  28. 1. Succeed
  29.    -recursive call
  30.     move next row
  31.     decrease # of queens
  32.     save the column position
  33.  
  34. 2. Failed
  35.    - return to previous call by decrementing the row and undo the attacked
  36.      position (see below).  Get the column that was saved and increment it
  37.      so that you can continue where you left off.  
  38.  
  39. To see if its valid to put a queen in a spot (won't be attacked by another
  40. queen) use arrays to represent the columns, positive and negative
  41. diagnols.. if its equal to 0 (you initialize them to zero) its a good
  42. spot, and then mark that spot with a -1.  Remeber to set the spot the last
  43. queen was placed back to 0 if you fail and return to the previous call.
  44.  
  45. -- 
  46.                                      ___
  47.                                    / 0 0 \
  48.                         ========oo0=(_)=0oo===========
  49.                         |\--------------------------/|
  50.                         ||       Chad Foster        ||
  51.                         || jcf3820@silver.sdsmt.edu ||
  52.                         ||      (605) 394-2768      ||
  53.                         |/------.ooo0---------------\|
  54.                         ========(   )=0ooo.===========
  55.                                   \ (  (   )
  56.                                    \_)  ) /
  57.                                        (_/
  58.